<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% String contextPath = request.getContextPath(); 
    request.setAttribute("contextPath", contextPath);%>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>下注设置</title>

    <!-- Bootstrap Core CSS -->
    <link href="${contextPath}/css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="${contextPath}/css/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="${contextPath}/css/sb-admin-2.min.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="${contextPath}/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!--common Css-->
    <link href="${contextPath}/css/common.css" rel="stylesheet">

    <!--information Css-->
    <link href="${contextPath}/css/information.css" rel="stylesheet">
    
    <link href="${contextPath}/iconfont/iconfont.css" rel="stylesheet">
</head>

<body>

<div id="wrapper">

        <!-- Navigation -->
         <%@include file="nav.jsp"%>

        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <h3 class="page-header">下注设置</h3>
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-6">
                   	<form action="">
                        <div class="form-group">
                            <label for="less" class="col-sm-2 control-label">最低投注彩钻</label>
                            <div class="col-xs-2">
                                <input type="text" class="form-control" id="less" name="less" value="${sessionScope.resultBet.data.betMin}" style="width: 80px; ">
                            </div>
                            <p class="form-control-static" >用户在每一注中最低能投注的彩钻数额</p>
                        </div>
                        <div class="form-group">
                            <label for="more" class="col-sm-2 control-label">最高投注彩钻</label>
                            <div class="col-xs-2">
                                <input type="text" class="form-control" id="more" name="more" value="${sessionScope.resultBet.data.betMax}" style="width: 80px; ">
                            </div>
                            <p class="form-control-static">用户在每一注中最高能投注的彩钻数额</p>
                        </div>
                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-3" style="position:relative;left:-130px">
                                <button type="button" class="btn btn-default" id="save">保存</button>
                                <button type="button" class="btn btn-default" id="reset">取消</button>
                            </div>
                        </div>
                   </form>
                </div>
            </div>
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="${contextPath}/js/jquery.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="${contextPath}/js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="${contextPath}/js/metisMenu.min.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="${contextPath}/js/sb-admin-2.min.js"></script>

    <!-- Page-Level Demo Scripts - Tables - Use for reference -->
    <script type="text/javascript">
        $(function() {
        $("#reset").click(function(){
        	$("#less").val(${resultBet.data.betMin});
        	$("#more").val(${resultBet.data.betMax});
        });
        $('[data-toggle="popover"]').popover();

            //点击保存
            $("#save").click(function(){
                var less = $("#less").val();
                var more = $("#more").val();
             	if(less == '' || more == ''){
             		$(".popupTip") .hide();
                    notice('请输入数据');
                    dispear();
                    return false;
                }
                var reg = /^[1-9][0-9]*$/;
                if (!reg.test(less) || !reg.test(more)) {
                	$(".popupTip") .hide();
                    notice('请输入正整数');
                    dispear();
                    return false;
                }
                 if (parseInt(less)>parseInt(more)) {
                	$(".popupTip") .hide();
                    notice('投注金额的下限不能高于上限');
                    dispear();
                   	return false;
                } 
                $.ajax({
              	url:'${contextPath}/WebManager/limitSetting/setlimit',
            	type:'POST',
            	data:JSON.stringify({
            		"betMin":less,
            		"betMax":more
            	}),
            	dataType:'json',
            	contentType:"application/json;charset=UTF-8",
            	success:function(data){
            	
            		if(data.message==='修改成功'){
            			$(".popupTip") .hide();
            			notice("修改成功");
            			dispear();
            		}else if(data.message==='修改操作异常停止了'){
            			$(".popupTip") .hide();
            			notice("修改操作异常停止了");
            			dispear();
            		}else if(data.message==='投注下限不能高于投注上限'){
            			$(".popupTip") .hide();
            			notice("投注下限不能高于投注上限");
            			dispear();
            		
            		}
            	}
                
                })
                
            });

            //提示信息封装函数
            function notice(notice) {
                var str = '';
                str += '<div class="popupTip">';
                str += notice;
                str += '<span class="glyphicon glyphicon-remove"></span>';
                str += '</div>';
                str += '</strong></div>';
                //wrapper插入str
                $("#wrapper").append(str);
            }

            //取消提示框
            $("#wrapper").on('click', '.glyphicon-remove', function() {
                $(".popupTip").hide();
            });

            function dispear(){
                setTimeout(function(){
                    $(".popupTip").hide();
                }, 3000);
            }
        })
    </script>

</body>

</html>